package com.room.search.service;

import com.room.search.domain.RoomRentBasic;
import com.room.search.repository.RoomRentBasicRepository;
import com.room.search.repository.search.RoomRentBasicSearchRepository;
import com.room.search.service.dto.RoomRentBasicDTO;
import com.room.search.service.mapper.RoomRentBasicMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link RoomRentBasic}.
 */
@Service
@Transactional
public class RoomRentBasicService {

    private final Logger log = LoggerFactory.getLogger(RoomRentBasicService.class);

    private final RoomRentBasicRepository roomRentBasicRepository;
    private final RoomRentBasicMapper roomRentBasicMapper;

    public RoomRentBasicService(RoomRentBasicRepository roomRentBasicRepository,
                                RoomRentBasicMapper roomRentBasicMapper) {
        this.roomRentBasicRepository = roomRentBasicRepository;
        this.roomRentBasicMapper = roomRentBasicMapper;
    }

    /**
     * Save a roomRentBasic.
     *
     * @param roomRentBasicDTO the entity to save.
     * @return the persisted entity.
     */
    @Transactional
    public RoomRentBasic save(RoomRentBasicDTO roomRentBasicDTO) {

        log.debug("Request to save RoomRentBasic : {}", roomRentBasicDTO);
        RoomRentBasic roomRentBasic = roomRentBasicMapper.toEntity(roomRentBasicDTO);
        roomRentBasic = roomRentBasicRepository.save(roomRentBasic);
        return roomRentBasic;
    }

    /**
     * Partially update a roomRentBasic.
     *
     * @param roomRentBasicDTO the entity to update partially.
     * @return the persisted entity.
     */
    public Optional<RoomRentBasicDTO> partialUpdate(RoomRentBasicDTO roomRentBasicDTO) {
        log.debug("Request to partially update RoomRentBasic : {}", roomRentBasicDTO);

        return roomRentBasicRepository
            .findById(roomRentBasicDTO.getId())
            .map(existingRoomRentBasic -> {
                roomRentBasicMapper.partialUpdate(existingRoomRentBasic, roomRentBasicDTO);

                return existingRoomRentBasic;
            })
            .map(roomRentBasicRepository::save)
            .map(roomRentBasicMapper::toDto);
    }

    /**
     * Get all the roomRentBasics.
     *
     * @return the list of entities.
     */
    @Transactional(readOnly = true)
    public List<RoomRentBasicDTO> findAll() {
        log.debug("Request to get all RoomRentBasics");
        return roomRentBasicRepository.findAll().stream().map(roomRentBasicMapper::toDto).collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     * Get one roomRentBasic by id.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    @Transactional(readOnly = true)
    public Optional<RoomRentBasicDTO> findOne(Long id) {
        log.debug("Request to get RoomRentBasic : {}", id);
        return roomRentBasicRepository.findById(id).map(roomRentBasicMapper::toDto);
    }

    /**
     * Delete the roomRentBasic by id.
     *
     * @param id the id of the entity.
     */
    public void delete(Long id) {
        log.debug("Request to delete RoomRentBasic : {}", id);
        roomRentBasicRepository.deleteById(id);
    }
}
